<template>
  <div>
    <header class="fxs order">
      <div class="info2">
        <div class="other fontGilroy">
          <div>
            <span>{{data.total_commissions}}</span>
            <p>我的{{data.commission_name}}(元)</p>
          </div>
          <div>
            <span>{{data.recommend_nums}}</span>
            <p>供应商数量(人)</p>    
          </div>
        </div>
      </div>
    </header>
    <div class="user-list"
         v-show="list.length">
      <van-list v-model="loading"
                :finished="finished"
                :error.sync="error"
                error-text="请求失败，点击重新加载"
                finished-text=""
                @load="onLoad">
        <div v-for="(item, index) in list"
             :key="index"
             class="item clearfix">
          <div class="levelimg fl">
            <img :src="item.logo"
                 v-if="item.logo"
                 width="100%"
                 alt />
            <img :src="defaultPhotoImg"
                 v-else
                 width="100%"
                 alt />
          </div>
          <div class="levelinfo fl">
            <p>
              <span>手机：</span>
              <span>{{item.mobile}}</span>
            </p>
            <p>
              <span>姓名：</span>
              <span>{{item.name}}</span>
            </p>
            <p>
              <span>创建时间：</span>
              <span>{{item.add_time}}</span>
            </p>
            <p>
              <span>到期时间：</span>
              <span>{{item.expiration_time}}</span>
            </p>
          </div>
        </div>
      </van-list>
    </div>
    <div v-show="!list.length && finished">
      <no-data :noData="noData"></no-data>
    </div>
  </div>
</template>

<script>
// import noDataImg from '@img/user/no_user_data.png'
// import default_photo_img from '@img/user/default_photo_img.jpg'
import noData from '@/components/noData/index'
import Scroll from '@/components/scroll/index'
import { getTgyRecommendSupplier } from '@/api/user/gys/gysApi'
import Vue from 'vue'
export default Vue.extend({
  data() {
    return {
      defaultPhotoImg: 'https://img.wifenxiao.com/h5-wfx/images/default_photo_img.jpg',
      noData: {
        text: '暂无会员',
        img: 'https://img.wifenxiao.com/h5-wfx/images/user/no_user_data.png',
        marginTop: '10em'
      },
      data: {
      },

      p: 2,

      loading: false,
      finished: false,
      error: false,
      list: []
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.$loadingWrap.show()
      getTgyRecommendSupplier().then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
          // 头部和导航数据
          this.data = res.data
          // 列表
          this.list = res.data.gys_list
          // 其它
          if (!this.list.length) {
            this.finished = true
          }
        } else {
          this.$Error(res.msg)
        }
      })
    },
    onLoad() {
      const data = {
        p: this.p
      }
      getTgyRecommendSupplier(data)
        .then(res => {
          this.loading = false
          if (res.data.gys_list.length) {
            this.list = this.list.concat(res.data.gys_list)
            this.p++
          } else {
            this.finished = true
          }
        })
        .catch(() => {
          this.error = true
        })
    }
  },
  components: {
    noData,
    Scroll
  },
  mounted() {
    // 小程序触底加载更多
    window.addEventListener("reachbottom", () => {
      this.onLoad()
    })
  }
})
</script>

<style lang="scss">
@import "src/styles/user/cardList/index.scss";
header {
  position: relative;
  width: 100%;
  .info2 {
    background: url(https://img.wifenxiao.com/h5-wfx/images/user/fenxiaoGood_bg.png) center no-repeat;
    text-align: center;
    margin: 0 auto;
    color: $default;
    overflow: hidden;
    height: 210px;
    padding-top: 56px;
    box-sizing: border-box;
    span {
      display: block;
      font-size: 50px;
      font-weight: bold;
    }
    p {
      margin-top: 20px;
      font-size: 26px;
      color: #ffd9dd;
    }
    .other {
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      &::before {
        content: "";
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 1px;
        height: 80px;
        background-color: #ff7c86;
      }
      div {
        flex: 1;
      }
    }
  }
}
</style>
